package BullFightGame;

public class HandPoker {

	public Deck[] decks = new Deck[5];
    private int[] high =new int[3];
    
	public HandPoker() {
	}

	private boolean test(int count, int start, Deck[] handpoker, int target) {
		if (count == 3 && target == 0) {
			return true;
		}
		if (start == handpoker.length) {
			return false;
		}
		return test(count + 1, start + 1, handpoker, target - handpoker[start].getValue())
				|| test(count, start + 1, handpoker, target);
	}

	public boolean Have() {
		boolean result = test(0, 0, decks, 10) || test(0, 0, decks, 20) || test(0, 0, decks, 30);
		return result;
	}

	public int Point() {
		int point = 0;
		for (Deck d : decks) {
			point += d.getValue();
		}
		point = point % 10;
		if (point == 0) {
			point = 10;
		}
		return point;
	}

	public String strPoint() {
		switch (Point()) {
		case 1:
			return "一";
		case 2:
			return "二";
		case 3:
			return "三";
		case 4:
			return "四";
		case 5:
			return "五";
		case 6:
			return "六";
		case 7:
			return "七";
		case 8:
			return "八";
		case 9:
			return "九";
		case 10:
			return "牛";
		default:
			return " ";
		}
	}

	public int getHighHand() {
		int highhand = 0;
		for (Deck d : decks) {
			highhand = Math.max(highhand, d.getLiteralnumber());
		}
		return highhand;

	}

	public String getHighHandPoker() {
		int highhand = 0;
		for (Deck d : decks) {
			highhand = Math.max(highhand, d.getNumber());
		}
		return Deck.numberToString(highhand);
	}

	public String show() {
		String str = "手牌：";
		for (Deck d : decks) {
			str += d.toString();
		}
		return str;
	}

	public String toString() {
		String str = "";
		str += show();
		str += "      ";
		if (Have()) {
			str += "有牛，牛" + strPoint() + "，";
		} else {
			str += "没牛，";
		}
		str += "最大" + getHighHandPoker();
		return str;
	}

    public void setHigh(){
    	if(Have()){
    		high[0]=1;   		
    		high[1]=Point();
    	}
    	else{
    		high[0]=0;
    		high[1]=0;    		
    	}
    	high[2]=getHighHand();
    }
    public int compare(HandPoker h){
    	this.setHigh();
    	h.setHigh();
    	if(high[0]>h.high[0]){
    		return 1;
    	}
    	else if(high[0]<h.high[0]){
    		 return -1;
    	}
    	if(high[1]>h.high[1]){
    		return 1;
    	}
    	else if(high[1]<h.high[1]){
    		 return -1;
    	}
    	if(high[2]>h.high[2]){
    		return 1;
    	}
    	else if(high[2]<h.high[2]){
    		 return -1;
    	}
    	return 0;
    	   
    }
}

